Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fallback_languages_per_field to TranslationOptions #507

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

wtayyeb
Copy link

@wtayyeb wtayyeb commented Apr 22, 2019

There is model_fallback_languages in TranslationOptions to define fallback languages for all fields.
but sometime we want to only fallback specific field and let other not to fallback or fallback on different languages. For example assume a model with title, description fields which we want to translate them for en, de but we want to fallback title to en when no translated version of it in de and don't fallback for description field. this is where fallback_languages_per_field will help us:

class MyModel(models.Model):
    title = models.CharField(...)
    description = models.TextField(...)
    ...

@register(MyModel)
class MyModelTranslationOptions(TranslationOptions):
    fields = ('title', 'description')
    fallback_languages_per_field = {
        'title': {'default': ('en', 'de'), },
    }

@last-partizan
Copy link
Collaborator

Well, it looks like simple change.

And probably useful one. Do you still want to merge it or do you found another way to do it for your case?

If you want to merge, then add some documentation and tests for this feature.

@wtayyeb
Copy link
Author

wtayyeb commented Nov 7, 2019

Absolutely I think this is important for any real world multilingual projects.

My workaround for all patches like this which are in waiting to merge state is to publish them as separate package with -pr000 suffix.
following link is for this PR and I use it since creation.
https://pypi.org/project/django-modeltranslation-pr507/

I will add tests and docs in next week.

@last-partizan
Copy link
Collaborator

Good, please add some docs here: https://github.com/deschler/django-modeltranslation/blob/master/docs/modeltranslation/registration.rst about this new option.

And tests, if you have idea about how to test it.

And the i'll merge it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants